<template>
  <div class="app-container">
    <div>
      <el-row class="admin-top-g">
        <GButton
          :is-add-show="!!(limits.length >= 1 && limits.filter(it => it.FName === '新增').length)"
          :is-edit-show="!!(limits.length >= 1 && limits.filter(it => it.FName === '修改').length)"
          :is-del-show="!!(limits.length >= 1 && limits.filter(it => it.FName === '删除').length)"
          :lists="options"
          :is-settings-show="lookSetShow"
          @onAdd="addUser"
          @onEdit="editUser"
          @onDelete="delUser"
          @selectSettings="selectSettings" />
      </el-row>
      <br>

      <el-row class="common-row">
        <template v-if="limits.length >= 1 && limits.filter(it => it.FName === '查看').length">
          <el-input
            v-model="keyword"
            clearable
            style="width: 200px;"
            placeholder="请输入关键字"
            @keyup.native.enter="searchUser"
            @change="searchUser" />

          <el-select v-model="ftypecheck" style="width:100px;" clearable placeholder="请选择" @change="selectFtypeCheck">
            <el-option
              v-for="item in ftypeCheckList"
              :key="item.value"
              :label="item.value"
              :value="item.key"/>
          </el-select>
          <el-button type="primary" icon="el-icon-search" @click="searchUser">搜索</el-button>
        </template>

        <!-- <el-upload
          v-if="limits.length >= 1 && limits.filter(it => it.FName === '导入').length"
          ref="uploadBasic"
          :on-preview="handlePreviewBasic"
          :on-remove="handleRemoveBasic"
          :limit="1"
          :data="upDataBasic"
          :on-exceed="exceedBasic"
          :on-success="noticeBasic"
          :file-list="fileListBasic"
          :before-upload="beforeAvatarUploadBasic"
          class="upload-demo"
          style="display: inline-block; margin-left: 0px;"
          action="/excel/zyImport">
          <el-button size="small" type="primary" icon="el-icon-upload">导入</el-button>
        </el-upload> -->

        <el-button
          v-if="limits.length >= 1 && limits.filter(it => it.FName === '导出').length"
          type="primary"
          icon="el-icon-download"
          @click="downData">导出</el-button>
        <!-- <el-button type="primary" icon="el-icon-download" @click="handleDownload">下载{{ fmofanName }}模板</el-button> -->

        <el-button
          v-if="limits.length >= 1 && limits.filter(it => it.FName === '审核').length"
          type="primary"
          icon="el-icon-circle-check"
          @click="check('1')">审核</el-button>
        <el-button
          v-if="limits.length >= 1 && limits.filter(it => it.FName === '反审核').length"
          type="primary"
          icon="el-icon-close"
          @click="fsCheck('0')">反审</el-button>
        <el-button
          v-if="limits.length >= 1 && limits.filter(it => it.FName === '退审').length"
          type="primary"
          icon="el-icon-close"
          @click="check('0')">退审</el-button>

        <el-button type="primary" icon="el-icon-mobile-phone" @click="vxeSendSms">发送信息</el-button>
        <el-button type="primary" icon="el-icon-refresh" @click="refresh">刷新 </el-button>
        <el-button
          v-if="limits.length >= 1 && limits.filter(it => it.FName === '未完成').length"
          type="primary"
          icon="el-icon-close"
          @click="finishBtn('0')">未完成</el-button>
        <el-button
          v-if="limits.length >= 1 && limits.filter(it => it.FName === '已完成').length"
          type="primary"
          icon="el-icon-finished"
          @click="finishBtn('1')">已完成</el-button>
      </el-row>
    </div>
    <br>
     
    <div style=" margin-top:-20px; ">
      <template v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length">
       
        <vxe-grid ref="xGrid" :header-cell-style="tableHeaderStyle"    :footer-method="footerMethod"   
   
        v-bind="gridOptions" :seq-config="{startIndex: (tablePage.currentPage - 1) * tablePage.pageSize}" 
         @checkbox-change="handleSelectionChange" 
        >

          <template #pager>
            <vxe-pager
              :layouts="['Sizes', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'FullJump', 'Total']"
              :current-page.sync="tablePage.currentPage"
              :page-size.sync="tablePage.pageSize"
              :total="tablePage.total"
              :pageSizes="[ 50, 100, 200, 500,1000,2000,5000 ]"
              @page-change="handlePageChange"/>
          </template>
        </vxe-grid>
      </template>
    </div>

    
    <!-- 参数配置 -->
    <el-dialog v-el-drag-dialog :visible.sync="configModal" :close-on-click-modal="false" class="config-dialog">
      <head-table :config-list="configList" :key-value="key" @updateConfigData="getUpdateConfigData" />
    </el-dialog>

    <!-- SQL弹窗 -->
    <el-dialog v-el-drag-dialog :visible.sync="dialogSQLModal" :append-to-body="true" title="执行结果">
      <el-form v-loading="loadingFormSQL" ref="formSQL" :rules="rulesSQL" :model="formSQL" label-width="120px">
        <el-form-item label="SQL语句" prop="gzsql">
          <el-input v-model="formSQL.gzsql" :autosize="{ minRows: 14 }" type="textarea" style="width:400px;" />
        </el-form-item>
        <el-form-item>
          <el-button :loading="loadingFormSQL" type="primary" @click="confirmSQL">确认</el-button>
          <el-button @click="dialogSQLModal = false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 下载模板 -->
    <el-dialog :visible.sync="tableSetExcel" title="提示：信息导出" style="width:30%; margin:auto;">
      <el-button type="primary" @click="downloadFile1()">导出</el-button>
    </el-dialog>

    <!-- SendMsg弹窗 -->
    <SendMsg
      :send-msg-info="sendMsgDialog"
      @confirmSendMsg="confirmSendMsg" />

  </div>
</template>
<script>
let FRepKey = ''
let opername = ''
const defaultFormThead = []

import HeadTable from '../salary/headTable/index.vue'
import { configColumn } from '../../api/salary'
import { download } from '../../mixins/download.js'
import { common } from '../../mixins/common'
import { pagination } from '../../mixins/pagination'
import { parseTime } from '../../utils/index'
import { tableConfig, apiSql, apiFileSave, downFileUrl } from '../../api/account'
import { sendsms, beijianTree, beijianDel, beijianStatus, UnCheckFstatus, beijianWancheng } from '../../api/peijian'
import { genAdd, genList } from '../../api/gen'
import '../../styles/common.scss'

export default {
  name: 'Index',
  components: {
    HeadTable
  },
  filters: {
    parseTime(time, type) {
      return parseTime(time, type)
    }
  },
  mixins: [download, common, pagination],
  data() {
    return {
      sendMsgDialog: {
        width: '50%',
        title: '发送信息',
        sendMsgLoading: false,
        dialogSendMsgModal: false,
        loadingFormSendMsg: false,
        userList: [],
        sendUsrList: [],
        formSendMsg: {},
        rulesSendMsg: {},
        defaultProps: {
          children: 'children',
          label: 'label'
        }
      },
      ftypecheck: 1,
      ftypeCheckList: [
        {
          key: 1,
          value: '未报价'
        },
        // {
        //   key: 2,
        //   value: '报价中'
        // },
        {
          key: 3,
          value: '已报价'
        },
        {
          key: 5,
          value: '已完成'
        },
        {
          key: 0,
          value: '全部'
        }
      ],
      value: '',
      options: [],
      FRepKey: '',
      keyword: '',
      fdeleted: '',
      fdeletedList: [

      ],
      fdeletedListDiaL: [

      ],
      gapTime: '',
      start_time: '',
      end_time: '',

      
      gridOptions: {
        border: true,
        // showHeaderOverflow: false,  
        showOverflow: true,
        // showFooterOverflow: false,
        keepSource: true,
        autoResize: false,
        resizable: true,

        height: this.heightGD(),
        showFooter: true,
        round: true,
        size: 'mini',

        id: 'full_edit_1',
        rowId: 'id',
        rowConfig: {
          isHover: true
        },
        // columnConfig: {
        //   resizable: true
        // },

        // 自定义列配置项
        customConfig: {
          storage: true,
          checkMethod: this.checkColumnMethod
        },

        keyboardConfig: {
          isEnter: true,
          isArrow: true
        },
 
 
        columns: [],
        data: [],

        checkboxConfig: {
          // labelField: 'id',
          reserve: true,
          highlight: true,
          range: true
        },

        editConfig: {
          trigger: 'click',
          mode: 'row',
          showStatus: true, // 是否显示单元格新增与修改状态
          showIcon: false // 是否显示列头编辑图标
          // activeMethod: this.activeRowMethod
        }

      },

      tablePage: {
        total: 0,
        currentPage: 1,
        pageSize: 50
      },



      // 表头、表格设置
      tableData: [],
      tableList: [],
      defaultFormThead: [],
      formThead: defaultFormThead,
      dialogThead: [],
      curData: {},
      selectData: {},
      columnData: [],

      listLoading: false,
      list: [],
      configModal: false,
      configLoading: false,

      loadingForm: false,
      configList: [],
      key: 0,
      // SQL弹窗
      dialogSQLModal: false,
      loadingFormSQL: false,
      formSQL: {
        gzsql: ''
      },
      rulesSQL: {

      },

      form: {},
      rules: {

      },
      addUserModal: false,
      // loadingForm: false

      fileList: [],

      // 批量删除
      selectedData: [],

      // 用户菜单
      menusList: [],
      limits: [],
      userKey: '',
      fmofanName: '',

      bmwzList: [ // 部门位置
        {
          finterid: 0,
          fname: '钢壳'
        },
        {
          finterid: 1,
          fname: '铝壳'
        },
        {
          finterid: 2,
          fname: '14500'
        }
      ],

      upData: {},
      fdeptname: '', // 部门
      bmList: [], // 部门
      xlList: [], // 学历
      zwList: [], // 职务
      xbList: [], // 性别
      lzztList: [],
      fileListBasic: [],
      baseList: [],
      upDataBasic: {},

      detail: '',
      opername: '',
      detailVisible: false,
      editText: false,
      tableSetExcel: false,
      lookSetShow: false,
      oriColumnData: [],

    }
  },

  async mounted() {
    this.userKey = this.$route.meta.FRepKey
    FRepKey = this.$route.meta.FRepKey
    this.upDataBasic.db = this.globalDb.db
    opername = decodeURIComponent(this.globalDb.fname)
    this.opername = decodeURIComponent(this.globalDb.fname)

    this.upDataBasic.FRepKey = this.$route.meta.FRepKey
    this.lookSetShow = JSON.parse(localStorage.getItem('flookSet'))

    this.upData.db = this.globalDb.db
    this.fmofanName = this.$route.meta.title

    // await this.getAllData()
    this.getHeadData() 
    this.getBodyData()

    // 菜单列表（权限）
    const menuRes = JSON.parse(localStorage.getItem('setMenuData'))
    this.menusList = menuRes
    if (menuRes.length >= 1) {
      menuRes.map(it => {
        it.children.map(item => {
          if (item.fobjectid === this.userKey) {
            this.$set(this, 'limits', item.child)
          }
        })
      })
    }
  },
  methods: {

      // 高度
      heightGD() {
      return (document.body.offsetHeight -170) + 'px'
    },

    // 分页
        handlePageChange({ currentPage, pageSize }) {
      this.tablePage.currentPage = currentPage
      this.tablePage.pageSize = pageSize
      this.getBodyData()
    },


    async vxeSendSms() {
      // console.log(this.selectedData, ' this.selectedData')
      // if (this.selectedData && this.selectedData.length) {
      if (this.selectedData && this.selectedData.length > 0 && this.selectedData.length <= 1) {
        this.sendMsgDialog.dialogSendMsgModal = true
        await this.getBeijianTree()
      } else {
        this.$message({
          message: '请选中一行信息',
          type: 'error'
        })
      }
    },
    async confirmSendMsg(selectMsgArr) {
      this.sendMsgDialog.dialogSendMsgModal = true
      try {
        const fcontent = this.sendMsgDialog.formSendMsg.fcontent
        const fbillno = this.selectedData[0].fbillno
        if (selectMsgArr.length) {
          const fid = selectMsgArr.join(',')
          if (!fid) {
            this.$message({
              message: '手机号为空',
              type: 'error'
            })
            return
          }

          const res = await sendsms({
            opername: decodeURIComponent(this.globalDb.fname),
            fid,
            fcontent,
            fbillno
          })
          // console.log(res, ' res')
          if (res.Error === 0) {
            this.sendMsgDialog.formSendMsg.fcontent = ''
            this.sendMsgDialog.dialogSendMsgModal = false
            this.selectedData.length = 0
            this.$refs.xGrid.clearCheckboxRow()

            this.$message({
              message: res.Message,
            })

          }
        } else {
          
          this.$message({
            message: '未选中发送信息通知人员',
            type: 'error'
          })
          return
        }
      } catch (error) {
        this.sendMsgDialog.dialogSendMsgModal = false
      }
    },
    async getBeijianTree() {
      try {
        this.sendMsgDialog.sendMsgLoading = true
        const res = await beijianTree({
          opername: decodeURIComponent(this.globalDb.fname)
        })
        // console.log(res, ' res')

        this.sendMsgDialog.sendUsrList = res.Data
        this.sendMsgDialog.sendMsgLoading = false
      } catch (error) {
        this.sendMsgDialog.sendMsgLoading = false
        console.log(error)
      }
    },
    // 刷新
    refresh() {
      window.location.reload()
    },

    async toDetail(data) {
      this.detailVisible = true
      this.detail = data
    },

    selectFBirthday(val) {
      this.form.fbirthday = parseTime(val, '{y}-{m}-{d}')
    },
    selectFHireDate(val) {
      this.form.fhiredate = parseTime(val, '{y}-{m}-{d}')
    },
    selectFLeaveDate(val) {
      this.form.fleavedate = parseTime(val, '{y}-{m}-{d}')
    },
    // -----------------上传开始---------------------
    beforeAvatarUpload(file) {
      var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
      const extension = testmsg === 'xls' || testmsg === 'xlsx'
      const isLt2M = file.size / 1024 / 1024 < 1
      if (!extension) {
        this.$message({
          message: '上传文件只能是 xls/xlsx格式!',
          type: 'warning'
        })
      }
      if (!isLt2M) {
        this.$message({
          message: '上传文件大小不能超过 1MB!',
          type: 'warning'
        })
      }

      const fd = new FormData()
      fd.append('file', file)

      if (extension) {
        return true
      } else {
        this.$message.warning('只能上传excel文件格式xls/xlsx')
        return false
      }
    },

    async submitUpload() {
      this.$refs.upload.submit()
    },

    handleRemove(file, fileList) {

    },
    handlePreview(file) {

    },
    exceed() {
      // 重复选择文件,弹出错误弹窗
      this.$message('最多仅支持上传一个文件')
    },
    notice(e) {
      if (e.code === 200) {
        this.$message(e.message)
      } else {
        this.$message(e.message)
      }
    },
    // -----------------上传结束---------------------
    // 表头数据
    async getAllHeadData() {
      try {
        this.listLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          FRepKey
        })
        this.listLoading = false
        this.formThead = res.Data
        this.oriColumnData = res.Data

        // this.tableList = []
        this.formThead.map(item => {
          this.tableList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        // this.tableData = this.tableList.slice()
        let tableTemp
        if (this.selectedData.length) {
          tableTemp = this.selectedData
        } else {
          tableTemp = this.tableList.slice()
        }

        // 获取显示表头键值对
        this.formThead.filter(item => {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        // const listData = this.tableList.slice()
        const listData = tableTemp.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.headerKeys.map(it => {
            this.listData[index][it] = item[it]
          })
        })

        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })

        this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.listLoading = false
      }
    },

    // 表体数据————erp职员列表
    async getAllBodyData() {
      try {
        this.listLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername,
          keyword: this.keyword,
          ftypecheck: this.ftypecheck,

          limit: this.total,
          page: this.currentPage,
          FRepKey
        })
        this.listLoading = false

        this.tableList = res.Data
        this.total = res.total
      } catch (error) {
        this.listLoading = false
      }
    },
    // 导出数据
    async downData() {
      await this.getAllBodyData()
      await this.getAllHeadData()
      await this.exportData()
    },
    async getAllData() {
      await this.getBodyData()
      await this.getHeadData()
    },

    selectSettings(val) {
      if (val === 0) {
        this.settings()
      } else if (val === 1) {
        this.dialogSQL()
      }
    },
    settings() {
      this.configModal = true
      this.getTableConfig()
    },

    // 更新数据
    async getUpdateConfigData() {
      await this.getTableConfig()
      await this.getBodyData()
      await this.getHeadData()
    },

    // SQL修改/更新
    async dialogSQL() {
      this.dialogSQLModal = true
      try {
        const res = await apiSql({
          db: this.globalDb.db,
          opername,
          FRepKey
        })

        if (res.Error === 0) {
          this.formSQL.gzsql = res.Data
          this.formSQL.FRepKey = FRepKey
        }
        setTimeout(() => {
          this.$refs['formSQL'].clearValidate()
        })
      } catch (error) {
        // console.log(error)
      }
    },

    confirmSQL() {
      this.$refs['formSQL'].validate(async(valid) => {
        if (valid) {
          try {
            this.formSQL.db = this.globalDb.db
            this.formSQL.opername = opername
            const res = await apiFileSave(this.formSQL)
            if (res.Error === 0) {
              this.dialogSQLModal = false
              this.$message({
                message: res.Message,
                type: 'success'
              })
            } else {
              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            // console.log(error)
          }
        } else {
          return false
        }
      })
    },

    async getTableConfig() {
      try {
        this.configLoading = true
        const res = await tableConfig({
          db: this.globalDb.db,
          opername,
          key: FRepKey
        })
        this.configList = res.Data
        this.key = FRepKey
        this.configLoading = false
      } catch (error) {
        this.configLoading = false
      }
    },

     

    
      // 字段
      async getHeadData() {
      const res = await configColumn(
        {
          db: this.globalDb.db,
          FRepKey
        }
      )
      this.oriColumnData = res.Data
      // setTimeout(() => {
      if (res.Data.length > 0) {
        this.columnData.push({
          type: 'seq',
          width: 50,
          fixed: 'left'
        })
        this.columnData.push({
          type: 'checkbox',
          width: 50,
          fixed: 'left'
        })

        for (let i = 0; i < res.Data.length; i++) {
          if (res.Data[i].frepfld === 'fstatus') {
            this.columnData.push({
              field: res.Data[i].frepfld,
              title: res.Data[i].frepcap,
              width: res.Data[i].frepwid > 0 ? res.Data[i].frepwid : 0,
              slots: {
                // 使用 JSX 渲染
                default: ({ row }) => {
                  if (row.fstatus === 1) {
                    return [
                      <el-tag>审核</el-tag>
                    ]
                  }
                }
              }
            })
          }else if (res.Data[i].frepfld === 'ftypecheck') {
            this.columnData.push({
              field: res.Data[i].frepfld,
              title: res.Data[i].frepcap,
              width: res.Data[i].frepwid > 0 ? res.Data[i].frepwid : 0,
              slots: {
                // 使用 JSX 渲染
                default: ({ row }) => {
                  if (row.ftypecheck === 5) {
                    return [
                      <el-tag>已完成</el-tag>
                    ]
                  }else if(row.ftypecheck === 4){
                    return [
                      <el-tag>已报价</el-tag>
                    ]
                  }
                }
              }
            })
          } else if (res.Data[i].frepfld === 'fyongjinbl') {
            this.columnData.push({
              field: res.Data[i].frepfld,
              title: res.Data[i].frepcap,
              width: res.Data[i].frepwid > 0 ? res.Data[i].frepwid : 0,
              slots: {
                // 使用 JSX 渲染
                default: ({ row }) => {
                  return  <span>{row.fyongjinbl * 100 +'%' }</span>
                }
              }
            })
          } else {
            
            if (res.Data[i].falign === 1) {
              this.columnData.push({
                field: res.Data[i].frepfld,
                title: res.Data[i].frepcap,
                // headerAlign: 'left',
                // align: 'right',
                width: res.Data[i].frepwid > 0 ? res.Data[i].frepwid : 0,
               
              })
            } else {
              this.columnData.push({
                field: res.Data[i].frepfld,
                title: res.Data[i].frepcap,
                width: res.Data[i].frepwid > 0 ? res.Data[i].frepwid : 0,
                 
              })
            }
          }
        }
        // console.log(3333333 ,this.columnData )
        this.gridOptions.columns = this.columnData
        
        this.formThead = res.Data





        // this.tableList = []
        this.formThead.map(item => {
          this.gridOptions.data.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })




        // 获取显示表头键值对
        this.formThead.filter(item => {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })

       
      }


      
    },



    // 表体数据————erp职员列表
    async getBodyData() {
      try {
        this.listLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername,
          keyword: this.keyword,
          ftypecheck: this.ftypecheck,

          // fstatus: this.fstatus,
          // limit: this.pagesize,
          // page: this.currentPage,
          page: this.tablePage.currentPage, 
          limit: this.tablePage.pageSize,

          FRepKey
        })
        // this.listLoading = false

        // this.tableList = res.Data
        this.total = res.total

         setTimeout(() => {
            this.tablePage.total = res.total
            this.gridOptions.data = res.Data
 
          }, 500)

      } catch (error) {
        // this.listLoading = false
      }
    },



    async selectFtypeCheck() {
      await this.getBodyData();

      // await this.getAllData()
      // this.$nextTick(() => {
      //   this.$refs['bjTable'].doLayout();
      // })
    },
    async searchUser() {
      await this.getBodyData()
    },
    async handleSizeChange(val) {
      this.currentPage = 1
      this.pagesize = val
      await this.getBodyData()
    },
 
    salaryCurrentChange(val) {
      console.log(val, 'val salaryCurrentChange')
      this.curData = val
    },

    // 下载
    async handleDownload() {
      const res = await downFileUrl({
        db: this.globalDb.db,
        opername,
        FRepKey
      })
      if (res.Error === 0) {
        this.tableSetExcel = true
        this.url = res.Data
      } else {
        this.$message({
          message: res.Message,
          type: 'error'
        })
      }
    },

    downloadFile1() {
      this.tableSetExcel = false
      window.open('/api/downloadFile?FRepKey=' + FRepKey)
    },

    // -----------------上传模板开始---------------------
    beforeAvatarUploadBasic(file) {
      var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
      const extension = testmsg === 'xls' || testmsg === 'xlsx'
      const isLt2M = file.size / 1024 / 1024 < 1
      if (!extension) {
        this.$message({
          message: '上传文件只能是 xls/xlsx格式!',
          type: 'warning'
        })
      }
      if (!isLt2M) {
        this.$message({
          message: '上传文件大小不能超过 1MB!',
          type: 'warning'
        })
      }

      const fd = new FormData()
      fd.append('file', file)

      if (extension) {
        return true
      } else {
        this.$message.warning('只能上传excel文件格式xls/xlsx')
        return false
      }
    },

    async submitUploadBasic() {
      this.$refs.uploadBasic.submit()
    },

    handleRemoveBasic(file, fileList) {

    },
    handlePreviewBasic(file) {

    },
    exceedBasic() {
      // 重复选择文件,弹出错误弹窗
      this.$message('最多仅支持上传一个文件')
    },

    noticeBasic(e) {
      if (e.Error === 0) {
        this.$message(e.Message)
        this.getBodyData()
        this.$refs.uploadBasic.clearFiles()
      } else {
        this.$message(e.Message)
      }
    },

    // 添加
    async addUser(row) {
      // 跳转： &fid=' + row.fid
      this.$router.push('/peijian/peijianAdd?key=40001')
      return

      // this.editText = false
      // this.form = {}
      // const data = {}
      // this.dialogThead.map(item => { data[item.frepfld] = '' })
      // for (const i in data) {
      //   this.$set(this.form, i, data[i])
      // }
      // setTimeout(() => {
      //   this.$refs['form'].clearValidate()
      // })

      // this.addUserModal = true
    },

    // 修改
    async editUser() {
      const data = this.selectedData[0]
      console.log(data, 'data')

      if (data && Number(data.fstatus) === 1) {
        this.$message({
          message: '已审核，不能修改！',
          type: 'error'
        })
        return
      }

      this.editText = true
      this.form = {}
      if (this.selectedData.length !== 1) {
        this.$message({
          message: '请选中要编辑的一行',
          type: 'warning'
        })
        return
      }

      this.$router.push('/peijian/peijianAdd?key=40001&fbillno=' + data.fbillno)

      // this.dialogThead.map(item => { this.$set(this.form, item.frepfld, '') })
      // this.form.fid = 0

      // console.log(this.form, 'this.form')
      // this.selectData.iseditor = true
      // this.addUserModal = true
      // for (const i in this.form) {
      //   this.form[i] = data[i]
      //   this.dialogThead.map(item => {
      //     if (item.frepmeg === 1 && i === item.frepfld && !data[i]) {
      //       this.form[i] = ''
      //     }
      //   })
      // }
    },
    celledit(row, column, cell, event) {
      cell.contentEditable = true
      cell.focus()
    },

     

    async delUser() {
      const delData = this.selectedData[0]
      console.log(delData, 'delData')

      if (this.selectedData.length < 1) {
        this.$message({
          message: '请选中要删除的行',
          type: 'warning'
        })
        return
      }

      const dataTemp = this.selectedData
      const isFstatus = dataTemp.filter(it => Number(it.fstatus) === 1)

      if (isFstatus.length) {
        this.$message({
          message: '已审核，不能删除！',
          type: 'error'
        })
        return
      }

      // console.log(dataTemp.length, ' dataTemp')
      // ftypebaojia1
      const ftypecheckIs3 = dataTemp.filter(it => Number(it.ftypecheck) > 3)
      if (ftypecheckIs3.length) {
        this.$message({
          message: '不能删除！',
          type: 'error'
        })
        return
      }

      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        cancelButtonClass: 'btn-custom-cancel',
        type: 'warning'
      }).then(async() => {
        const finterid = this.selectedData.map(it => it.finterid).join(',')
        const fmainid = this.selectedData.map(it => it.fmainid).join(',')
        // const fid = data.join(',')
        const res = await beijianDel({
          db: this.globalDb.db,
          finterid,
          fmainid,
          opername,
          FRepKey
        })
        if (res.Error === 0) {
          this.$message({
            message: res.Message,
            type: 'success'
          })
          await this.getBodyData()
          return
        }
        this.$message({
          message: res.Message,
          type: 'error'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },

    
    // 合计
    footerMethod({ columns, data }) {
      const sums = []
      columns.forEach((column, columnIndex) => {
        this.aaValue = ''
        if (columnIndex === 0) {
          sums.push('合计')
        } else {
          this.oriColumnData.forEach((item, itemIndex) => {
            if (column.property === item.frepfld && item.frepsum === 1) {
              this.aaValue = item.frepfld
              return false
            }
          })
          if (column.property === this.aaValue) {
            sums.push(this.sumNum(data, column.property))
          } else {
            sums.push('')
          }
        }
      })
      // 返回一个二维数组的表尾合计
      return [sums]
    },
 

    sumNum (list, field) { // DONE
      let sumArr = []
      list.forEach(item => {
        sumArr.push(Number(item[field]))
      })
      if (!sumArr.length) {
        return 0
      }
      let sumList = this.decimal.add(...sumArr)
      return sumList
    },
    // 1—审核，0—反审
    async check(Fstatus) {
      const chData = this.selectedData[0]
      if (!this.selectedData.length) {
        this.$message({
          message: '请选择表格行数据',
          type: 'error'
        })
        return
      }
      if (this.selectedData.length > 1) {
        this.$message({
          message: '请选中一行信息',
          type: 'error'
        })
        return
      }
      if (Number(Fstatus) === 1) {
        this.$confirm('是否审核, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          cancelButtonClass: 'btn-custom-cancel',
          type: 'warning'
        }).then(async() => {
          try {
            const res = await beijianStatus({
              db: this.globalDb.db,
              finterid: chData.finterid,
              Fstatus, // 1—审核，0—反审
              opername,
              data: this.selectedData,
              FRepKey
            })
            if (res.Error === 0) {
              this.$message({
                message: res.Message,
                type: 'success'
              })
              await this.getBodyData()
              this.selectedData = []
              this.$refs.xGrid.clearCheckboxRow()
            } else {
              this.loadingForm = false
              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            console.log(error)
          }
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
      } else {
        try {
          const res = await beijianStatus({
            db: this.globalDb.db,
            finterid: chData.finterid,
            Fstatus, // 1—审核，0—反审
            opername,
            FRepKey,
            data: this.selectedData
          })
          if (res.Error === 0) {
            this.$message({
              message: res.Message,
              type: 'success'
            })
            await this.getBodyData()
            this.selectedData = []
            this.$refs.xGrid.clearCheckboxRow()
          } else {
            this.loadingForm = false
            this.$message({
              message: res.Message,
              type: 'error'
            })
          }
        } catch (error) {
          console.log(error)
        }
      }
    },
    async fsCheck(Fstatus) {
      const chData = this.selectedData[0]
      if (!this.selectedData.length) {
        this.$message({
          message: '请选择表格行数据',
          type: 'error'
        })
        return
      }
      if (this.selectedData.length > 1) {
        this.$message({
          message: '请选中一行信息',
          type: 'error'
        })
        return
      }
      try {
        const res = await UnCheckFstatus({
          db: this.globalDb.db,
          finterid: chData.finterid,
          Fstatus, // 1—审核，0—反审
          opername,
          FRepKey,
          data: this.selectedData
        })
        if (res.Error === 0) {
          this.$message({
            message: res.Message,
            type: 'success'
          })
          await this.getBodyData()
          this.selectedData = []
          this.$refs.xGrid.clearCheckboxRow()
        } else {
          this.loadingForm = false
          this.$message({
            message: res.Message,
            type: 'error'
          })
        }
      } catch (error) {
        console.log(error)
      }
    },
    async finishBtn(fisqr) {
      const chData = this.selectedData[0]
      if (!this.selectedData.length) {
        this.$message({
          message: '请选择表格行数据',
          type: 'error'
        })
        return
      }
      try {
        const res = await beijianWancheng({
          db: this.globalDb.db,
          finterid: chData.finterid,
          fisqr, // 1—已完成，0—未完成
          opername,
          data: chData,
          FRepKey
        })
        if (res.Error === 0) {
          this.$message({
            message: res.Message,
            type: 'success'
          })
          await this.getBodyData()
          this.selectedData = []
          this.$refs.xGrid.clearCheckboxRow()
        } else {
          this.loadingForm = false
          this.$message({
            message: res.Message,
            type: 'error'
          })
        }
      } catch (error) {
        console.log(error)
      }
    },
 

      //当手动勾选并且值发生改变时触发的事件
      handleSelectionChange(val) {
      this.checkData = []
      this.selectedData = val.records
      val.records.map(it => {
        this.checkData.push(it.fid)
      })
 
    },

  }
}

</script>
<style lang="scss" scoped>
.config-dialog ::v-deep .el-dialog {
  width: 90%;
}
.main-wrapper ::v-deep .single-select-table thead .el-table-column--selection .cell {
  display: none;
}
</style>
